package com.quanyan.assets.mq;

import com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import com.alibaba.rocketmq.common.message.MessageExt;
import com.quanyan.assets.constants.AssetsConstants;
import com.quanyan.assets.service.MqConsumerService;
import com.quanyan.common.constants.Constants;
import com.quanyan.mq.enums.MqConsumerStatus;
import com.quanyan.mq.mq.consumer.AbstractMqConsumer;
import com.quanyan.mq.mq.consumer.MqTopic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;

/**
 * Created by wmb on 2017/1/13.
 */
@Component("batchModifyEggConsumer")
public class BatchModifyEggConsumer extends AbstractMqConsumer {
    @Value("${mq.nameServer.address}")
    private String nameServerAddress;
    @PostConstruct
    void run() {
        super.start();
    }
    @Autowired
    private MqConsumerService mqConsumerService;
    @Override
    protected MqConsumerStatus process(List<MessageExt> messages, ConsumeConcurrentlyContext context) {
        //处理自身业务逻辑
        MessageExt messageExt = messages.get(0);
        //处理订单系统支付成功消息
        mqConsumerService.batchModifyEgg(messageExt);
        return MqConsumerStatus.CONSUMER_SUCCESS;
    }

    @Override
    protected String getConsumerGroup() {
        return AssetsConstants.ASSETS_GROUP_BATCH_ADD_EGG;
    }

    @Override
    protected String getNameServerAddress() {
        return this.nameServerAddress;
    }

    @Override
    protected String getInstanceName() {
        return AssetsConstants.ASSETS_INSTANCE_BATCH_ADD_EGG;
    }

    @Override
    protected MqTopic[] getMqTopics() {
        MqTopic[] mqTopics = new MqTopic[1];
        mqTopics[0] = new MqTopic(AssetsConstants.ASSETS_BATCH_MODIFY_EGG, Constants.ASSETS_SYSTEM_CODE); //订阅订单系统支付完成的相关的topic与tag.
        return mqTopics;
    }
}
